<?php
/**
 * egany_discount_setting
 * Author: PhongND
 * Author URI: http://www.facebook.com/
 * @package     WooCommerce/Admin
 * Version: 1.0
 */
 
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}


if ( ! class_exists( 'egany_discount_setting' ) ) :


class egany_discount_setting extends WC_Settings_Page {

    /**
     * Constructor
     */
    public function __construct() {

        $this->id    = 'egany_discount_id';

        add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_tab' ), 50 );
        add_action( 'woocommerce_sections_' . $this->id, array( $this, 'output_sections' ) );
        add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) );
        add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) );
		
		// //processing metabox, nono
		// include_once( 'egany-admin-metabox.php' );
		
    }

    /**
     * Add plugin options tab
     *
     * @return array
     */
    public function add_settings_tab( $settings_tabs ) {
        $settings_tabs[$this->id] = __( 'Discount Offer', 'egany_discount_domain' );
        return $settings_tabs;
    }

    /**
     * Get sections
     *
     * @return array
     */
    public function get_sections() {

        $sections = array(
            ''         => __( 'Plugin Options', 'egany_discount_domain' ), /// remove "section-0"

        );

        return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
    }


    /**
     * Get sections
     *
     * @return array
     */
    public function get_settings( $section = null ) {

        switch( $section ){

            case '' :
                $settings = array(
                    'section_title' => array(
                        'name'     => __( 'Section 01', 'egany_discount_domain' ),
                        'type'     => 'title',
                        'desc'     => '',
                        'id'       => 'hwif_section01'
                    ),
                    'chkOrder_DoHooks' => array(
                        'name' => __( 'Show notice', 'egany_discount_domain' ),
                        'type' => 'checkbox',
                        'desc' => __( 'Increase all amounts below.', 'egany_discount_domain' ),
                        'id'   => 'hwif_chkOrder_DoHooks'
                    ),
                    'txtMessage' => array(
                        'name' => __( 'Notice message', 'egany_discount_domain' ),
                        'type' => 'text',
                        'desc' => __( 'Notice message....', 'egany_discount_domain' ),
                        'id'   => 'hwif_txtMessage'
                    ),
                    'section_end' => array(
                         'type' => 'sectionend',
                         'id' => 'hwif_section02_end'
                    )
                );

            break;
        }

        return apply_filters( 'wc_settings_discount', $settings, $section );

    }

    /**
     * Output the settings
     */
    public function output() {
        global $current_section;
		if ($current_section) // trim($current_section) == ""
		{
			$settings = $this->get_settings( $current_section );
			
		}
		else
		{
			$settings = $this->get_settings("");
		}
        
        WC_Admin_Settings::output_fields( $settings );
    }


    /**
     * Save settings
     */
    public function save() {
        global $current_section;
        $settings = $this->get_settings( $current_section );
        WC_Admin_Settings::save_fields( $settings );
    }

}

return new egany_discount_setting();

endif;

